package cn.kgm.makeGodV2.event;

import cn.kgm.makeGodV2.GamePlayer;
import cn.kgm.makeGodV2.WorldState;
import cn.kgm.makeGodV2.outCome.EventOutcome;
import lombok.Builder;
import lombok.Data;

import java.util.List;
import java.util.function.Predicate;

/**
 * 事件选择
 *
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-16 10:36
 * @Description: cn.kgm.makeGodV2.eventChoice.EventChoice
 */
@Data
@Builder
public class EventChoice {
    private String id;
    private String text;
    private Predicate<GamePlayer> condition;
    private List<EventOutcome> outcomes;
    private double weight;

    public EventChoice(String id, String text, Predicate<GamePlayer> condition,
                       List<EventOutcome> outcomes, double weight) {
        this.id = id;
        this.text = text;
        this.condition = condition;
        this.outcomes = outcomes;
        this.weight = weight;
    }

    public boolean isAvailable(GamePlayer npc) {
        return condition.test(npc);
    }

    public void applyOutcomes(GamePlayer npc, WorldState worldState) {
        for (EventOutcome outcome : outcomes) {
            outcome.apply(npc, worldState);
        }
    }

    public double getWeight() {
        return weight;
    }
}
